package com.qfjy.homework.GaoZhongMing;

import java.util.HashMap;
import java.util.Map;

public class Context {
    //缓存所有的策略 当前是无状态的 可以共享策略类对象
    private  static final Map<String,GearStrategy> strategies = new HashMap<>();

    //第一种写法
    static {
        strategies.put("one",new GearStrategyOne());
    }
    public static GearStrategy getStrategy(String type){
        if (type ==null || type.isEmpty()){
            throw new IllegalArgumentException("type should not be empty.");
        }
        return strategies.get(type);
    }

    // 第⼆种写法
    public static GearStrategy getStrategySecond(String type) {
        if (type == null || type.isEmpty()) {
            throw new IllegalArgumentException("type should not be empty.");
        }
        if (type.equals("one")) {
            return new GearStrategyOne();
        }
        return null;
    }


}
